type Name = string;
type NameResolver = () => string;
type NameOrResolver = Name | NameResolver;
function getName(n: NameOrResolver): Name {
    if (typeof n === 'string') {
        return n;
    } else {
        return n();
    }
}
// 使用type创建类型别名
// 类型别名常用于联合类型


// 字符串字面量类型：用来约束取值只能是某几个字符串中的一个
type EventNames = 'click' | 'scroll' | 'mousemove';
function handleEvent(ele: Element, event: EventNames){
  console.log(11);
}
handleEvent(document.getElementById('hello'), 'scroll');
